package shuzu;

import org.junit.Test;

/**
 * Created by leiylong on 2020/6/5
 */
public class ShuZu {
    @Test
    public void test1(){
        int[] ne={1,2,3};
        for(int i=0;i<ne.length;i++){
            System.out.println(ne[i]);
        }
        String ne1[]={"雷","网"};
        for(int i=0;i<ne1.length;i++){
            System.out.println(ne1[i]);
        }

    }
    //二维数组
    @Test
    public void test2(){
        int[][] ne2={{1,2,3},{4,5,6}};
        //外围数组{},有两个元素
        //给外围数组赋值，3个元素123,456
        //普通for循环
        System.out.println("//普通for循环");
        for(int i=0;i<ne2.length;i++){
            for (int j=0;j<ne2[i].length;j++){
                System.out.println(ne2[i][j]+",");
            }
        }
        //增强for循环
        System.out.println("//增强for循环");
        for(int[] arr:ne2){
            for(int i:arr){
                System.out.println(i);
            }
        }
    }

    //冒泡排序
    @Test
    public void test3(){
        int[] arr={5,34,23,54,12,2};
        //普通数组
        System.out.println("普通循环");
        for(int sum:arr){
            System.out.print(sum+",");
        }
        System.out.println("排列后的数组");
        for(int i=0;i<arr.length-1;i++){
            for(int j=0;j<arr.length-1-i;j++){
                if(arr[j]>arr[j+1]){
                    //交换
                    int team=arr[j];
                    arr[j]=arr[j+1];
                    arr[j+1]=team;
                }
            }
        }
        for(int t:arr){
            System.out.print(t+",");
        }
    }

}
